<template>
	<view>
		<!-- 搜索框 -->
		<view class="search_view">
			<u-search
				shape="square"
				:show-action="true" 
				action-text="搜索" 
				:clearabled="true"  
				:animation="true" 
				:focus="true"
				v-model="keywords"
				@search="search"
				>
			</u-search>
		</view>
		<view class="list" v-if="buffer">
			<view class="row" v-for="(item,index) in list" >
				<image :src="item.img" mode="widthFix"></image>
				<view class="info">
					<text>{{item.goodsname}}</text>	
					<text>￥{{item.price}}</text>	
					<text>3565评论</text>	 
				</view>
			</view>
		</view>
		<view class="api" v-else>
			没有数据亲！
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buffer:true,//页面显示开关,
				keywords:'',//初始化搜索关键词
				list:[]
			}
		},
		onLoad(options){
			
		},
	
		methods: {
			async search(value){
				
				// console.log(value,1111111);
				//发起请求 http://localhost:3000/api/search    
				let [err,res] = await uni.request({
					
					url:this.$baseUrl+"/api/search",
					data:{
						keywords:this.keywords
					}
					
				})
				if(err){
					uni.showToast({
						title:"加载中...",
						icon:"loading"
					})
					return
				}
				if(res.data.code!=200){
					uni.showLoading({
						title:"加载中..."
						})
						return
				}
				if(!res.data.list){
					this.buffer=false

					return
				}
				res.data.list.forEach(item=>{
					item.img=this.$baseUrl+item.img
				})
				console.log(res);
				this.buffer=true
				this.list=res.data.list
			},
			
		},
		
	}
</script>

<style>
	/* 引入样式 */
	@import url("@/static/css/search.css");
</style>
